package org.rainbowinverted.charging.device.connect.bl.server.handler;

import cn.hutool.core.util.HexUtil;
import com.dix.codec.bkv.BKV;
import io.netty.channel.ChannelHandlerContext;
import org.rainbowinverted.charging.device.connect.bl.server.message.out.BlDeviceExecuteCmdOut;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author huaiping
 */
@Component
public class BlDeviceExecuteCmdHandler extends BlAbstractHandler<Void, BlDeviceExecuteCmdOut>{


    /**
     * 执行cmd
     *
     * @param deviceNo 设备编号
     * @param cmd      cmd
     * @return {@link Boolean}<{@link Boolean}>
     */
    public Boolean executeCmd(Long deviceNo, String cmd) {
        ChannelHandlerContext channel = getChannel(deviceNo);
        if (Objects.nonNull(channel)) {
            channel.writeAndFlush(HexUtil.decodeHex(cmd));
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    @Override
    public void write(BlDeviceExecuteCmdOut message, BKV bkv) {

    }

    @Override
    public void read(ChannelHandlerContext channelHandlerContext, BKV bkv) {

    }
}
